	layui.use(['form', 'layedit', 'upload', 'laytpl'], function() {
		var form = layui.form,
			$ = layui.jquery,
			upload = layui.upload,
			laytpl = layui.laytpl,
			layedit = layui.layedit;
		form.render();
		var richdemo = layedit.build('tbIntroductionid'); //讲师简介
		var router = layui.router(); //获取路由
//执行实例

		var upimage1file = upload.render({
			elem: '#image1file',
			url: HH_URL + FileUp,
			acceptMime: 'image/*',
			size: '800',
			accept: 'images',
			data: {
				fileType: 5
			},
			headers: {
				"ticket": JSON.parse(localStorage.getItem('HH_T')).ticket
			},
			done: function(res) {
				console.log(res)
				if (res.status == 200) {
					$("#image1id").val(res.data.filePath);
					$("#image1file").html('	<img src="' + IMG_URL + res.data.filePath + '" >');
					layer.msg("上传成功", {
						"icon": 1
					});
				}
			},
			error: function() {
				//请求异常回调
			}
		});


		var sourcetypejson = [],
			newsourcejson = []; // 类型json
		POSTAJAX(VtypeGet, {
			currentPage: 1,
			pageSize: 1000,
			tbName: ''
		}, function(res) {
			$.each(res.data.data, function(idx, obj) {
	
				$("#bqid").append( '<div class="bq bq2 cupo">'+ obj.tbProdustsTypeName+'</div>');
			})
			form.render();
			form.on('select(teachertypefilter)', function(data) {
				sourcetypejson.push(data.value);
				var $index = data.elem.selectedIndex;
				if ($index != 0) {
					
					$("#typebox").append('<div class="asource " data-id="' + data.value + '">	' + data.elem[data.elem.selectedIndex]
						.text +
						' &#x1006;	</div>');

					$(".asource").on("click", function() {

						$(this).remove();
						delete arr[$(this).index()];
					})
				}


			})
		})



//讲师列表
		var lecturerjson = [],
			newlecturerjson = []; // 类型json
		POSTAJAX(LecturerGet, {
			currentPage: 1,
			pageSize: 1000,
		}, function(res) {
			$.each(res.data.data, function(idx, obj) {
	
				$("select[name='userId']").append( '	<option value="'+obj.tbLecturerID+'">'+obj.tbName+'</option>');
			})
			form.render();
			form.on('select(teachertypefilter)', function(data) {
			
			})
		})


		if (router.search.tbId) {
			// 有id的传参的值  查询 id
			POSTAJAX(LecturerOById, {
				tbId: router.search.tbId
			}, function(res) {
				form.val("teacheraddfilter", {
					"cname": res.data.cname,
					"pname": res.data.pname,
					"tbCityId": res.data.tbCityId,
					"tbGraduationSchool": res.data.tbGraduationSchool,
					"tbHeadPortrait": res.data.tbHeadPortrait,
					"id": res.data.tbId,
					"tbIdCard": res.data.tbIdCard,
					"tbIntroduction": res.data.tbIntroduction,
					"tbLecturerID": res.data.tbLecturerID,
					"tbName": res.data.tbName,
					"tbPassword": res.data.tbPassword,
					"tbPhone": res.data.tbPhone,
					"tbProvinceId": res.data.tbProvinceId,
					"tbSex": res.data.tbSex,
					"tbSourceId": res.data.tbSourceId,
					"tbSourceName": res.data.tbSourceName,
					"tbWorkingLife": res.data.tbWorkingLife
				})


				$("#upheadimgfile").html('	<img src="' + IMG_URL + res.data.tbHeadPortrait + '" >');

				layedit.setContent(richdemo, res.data.tbIntroduction);

			})

			//修改
			form.on('submit(formDemo)', function(data) {
				if (layedit.getContent(richdemo) == '') {
					layer.msg("请输入详情内容", {
						"icon": 7
					})
				} else {
					// data.field.tbAgreementContent = layedit.getContent(richdemo)
					// data.field.tbId = router.search.tbId;
					POSTAJAX(BannerMod, data.field, function(res) {
						if (res.status == 200) {
							layer.msg("修改成功", {
								"icon": 1
							})
							form.render();
							location.href = '#/setup/list'
						} else {
							layer.msg("失败，请重试", {
								"icon": 2
							})
						}
					})
				}
				return false;
			});
		} else {
			// 新增
			//监听提交
			form.on('submit(formDemo)', function(data) {

				if (layedit.getContent(richdemo) == '') {
					layer.msg("请输入详情内容", {
						"icon": 7
					})
				} else {
					data.field.tbIntroduction = layedit.getContent(richdemo)
					// data.field.addIds.push(data.field.addIdsstring);
					// data.field.tbId.
					var tpostjson = data.field;
					tpostjson.addIds = sourcetypejson;
					POSTAJAX(LecturerAdd, tpostjson, function(res) {
						if (res.status == 200) {
							layer.msg("新增成功", {
								"icon": 1
							})
							richdemo = layedit.build('demo');
							form.render();
							location.href = '#/teacher/list'
						} else {
							layer.msg(res.msg, {
								"icon": 2
							})
						}
					})
				}
				return false;
			});

		}
		$("#returnqx").on("click", function() {
			location.href = '#/teacher/list';

		})


	});